package com.edu.fafu.studentrepair.command;

import android.content.Context;
import android.util.Log;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class LocalDataStream {
    public static void writer(String str, FileOutputStream out){
        BufferedWriter writer = null;
        try{
            writer = new BufferedWriter(new OutputStreamWriter(out));
            Log.i("writer", "login: "+str);
            writer.write(str);
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            try{
                if(writer != null)
                    writer.close();
            }catch (IOException e){
                e.printStackTrace();
            }
        }
    }

    public static String read(FileInputStream in)  {
        BufferedReader reader = null;
        String line = "";
        StringBuilder content = new StringBuilder();
        try{
            reader = new BufferedReader(new InputStreamReader(in));
            while((line = reader.readLine()) != null)
                content.append(line);
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            try{
                if(reader != null)
                    reader.close();
            }catch (IOException e){
                e.printStackTrace();
            }
        }
        return content.toString();
    }
}
